import 'package:flutter/material.dart';

import '../public.dart';

class SliderAnimation extends StatelessWidget {
  SliderAnimation(
      {this.child,
      this.animation,
      this.type = EnumSliderAnimationComponent.type1});

  final Widget child;
  final Animation<dynamic> animation;
  final EnumSliderAnimationComponent type;

  Widget build(BuildContext context) {
    return AnimatedBuilder(
        animation: animation,
        builder: (BuildContext context, Widget child) {
          switch (type) {
            case EnumSliderAnimationComponent.type1:
              return buildType1();
              break;
            case EnumSliderAnimationComponent.type2:
              return buildType2();
              break;
            default:
              return buildType1();
          }
        },
        child: child);
  }

  buildType1() {
    return SlideTransition(position: animation, child: child);
  }

  buildType2() {
    return Transform.translate(
        offset: Offset(animation.value, 0.0), child: child);
  }
}

/// 实体状态类型
enum EnumSliderAnimationComponent {
  /// 传入offset 使用
  type1,

  /// 使用相对位置值偏移
  type2
}
